Skip to content

Reimpl/viewport render state - #241

Draft
gynt wants to merge 146 commits into
mainfrom
reimpl/ViewportRenderState
Draft

gynt wants to merge 146 commits into
mainfrom
reimpl/ViewportRenderState

Conversation

@gynt

@gynt gynt commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

No description provided.

gynt added 30 commits September 27, 2026 22:11
gynt and others added 4 commits November 8, 2026 21:34
…0 first

Both flat-view terrain chains (main pass and second pass) put the
logic & 0x100 arm first and the rocks/trees arm last, as the original.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmYbLQCBa8ek5RWjimR
…image first, moat arm without goto

41.1%, unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmYbLQCBa8ek5RWjimR
…a sprite switch

The entity pass over a tile is a do-while over nextEntityOnThisTileByID;
the sprite switch's cases follow the original's jump-table order, the
skip cases set a flag instead of jumping, the zoomed-out case advances
and continues, and the batch-scheduling default (which the decompiler
had parked after the function's return) sits at the end of the switch.
One goto stays: the fire case jumps to the default's schedule call,
which the original shares. 41.1%, unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmYbLQCBa8ek5RWjimR
…out goto

One rotateByteLeft call per orientation; MSVC merges them into the
original's shared call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmYbLQCBa8ek5RWjimR
@github-actions github-actions Bot added the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 9, 2026
gynt and others added 2 commits November 9, 2026 10:17
…the original's case order

Both siege-unit offset switches were still in Ghidra's value order; the original's
jump tables put mangonel after shield (found by switch_order.py). Also drops a
doubled (int) cast on drawHeight1 (dropcast.py, code-generation neutral).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmYbLQCBa8ek5RWjimR
…rder levers

The big decompiled render functions were held back mostly by block order, and
these are the scripts that restored it, cleaned up from the ViewportRenderState
session:

- switch_order.py: decode the original's jump tables, match each to a source
  switch, and put the case bodies in target-address order (= source order).
  Fall-through chains move as one unit, so a reorder cannot change behaviour.
  Reproduces the hand reorder of renderGmOverlayBuilding (0.40 -> 0.69 quick
  ratio) without the chopping-block fall-through the hand version introduced.
- flip_branches.py: flip if/else arms (inverted comparison, arms exchanged);
  --find pairs basic blocks against the original and lists the branches laid
  out the other way round.
- dropcast.py + test_dropcast.py: drop (int) casts integral promotion makes
  redundant, typed from the generated headers.
- make_variants.py: write quick_styles variants from (old, new) replacements.
- orig_emulate.py: run an original function under unicorn and dump `this`.
- quick_diff.py: -r (register-canonical), -l (source lines), --runs N,
  --sbs A-B; records control flow for flip_branches; argv parsed in main().
- quick_styles.py: exact/reg/fine scores, a (current) baseline row, --rank,
  and an identical-code marker.
- common.py: OriginalImage, shared by quick_diff, switch_order, orig_emulate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmYbLQCBa8ek5RWjimR
gynt added a commit that referenced this pull request Nov 24, 2026
…d_0x41a as a short (#450)

* headers: Unit::field_0x41a is a short

It was `undefined2`. Units::UpdateAssassin (0x005744D0) compares it signed in two places, `cmp ax, bx; jle` at
0x00574F12 and `cmp cx, bx; jle` at 0x005750C2 (ebx is 0), each followed by `add ..., -2` and the store back.
No other function on main names the field. The only other code that touches it is 0x004E2630 (`movsx` at
0x004E2691), not on main; gynt's #241 has it as renderAssassinClimbingOverlay and makes the same change to this
line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x005744D0 100.0% Reimplemented

Units::UpdateAssassin, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (7e9039d at 44.69%,
after 7ffb455 at 44.69% and 982d7f0 at 39.56%), through versions on our dev branch from 82.5% to 97.0%. The
forms that matter:
- the melee and wall-attack states have UpdateKnight's shapes: the unit is read through the slot global with no
  local copy of the unit ID, and the attacked unit's ID is read once into a local in front of
  playHurtSFXForUnit, its type once into an int behind it;
- `building` is declared with its value at the wall attack's tile check (`int building = BuildingLayer[...]`), so
  no path reads it unassigned; without that assignment the function gets 4 bytes of frame the original does not
  have;
- the fade countdown is decremented as a signed char (`--(char&)...`);
- of the wall attack's three give-up places the first and the third only set the state and fall to the case's
  end, and the second, the AI's give-up on a wall, is the then-arm of its test with the return in the else-arm.
  The compiler keeps a block with its own copy of the case's end at the first place and jumps into it from the
  second, as the original does (9 bytes);
- the idle state's end in its plain form: `if (dig or fill moat) { idle = 1; } if (idle == 0) { return; }
  animationCycleNumber = 0;`. The original sets the idle flag behind the two compares and jumps over the flag test
  (`cmp ax, 6; je; cmp ax, 7; jne; mov [idle], ecx; jmp` from 0x00575506); with the return in an else-if the
  function is four instructions longer;
- field_0x41a is compared as the short it now is in Unit.hpp (the commit before this one), without a cast.
The rope chain ends in an else-if / else, no else stands behind a return, and two comments give the why of the
then-arm and of the signed decrement; the code is the same (quick_diff, 1058 instructions, line for line).
Numbers and pointer arithmetic that have names in main's headers are written with those names, as in
UpdateKnight. The states 104 and 105 have no name in UnitState yet and keep their casts.

compiler-flags-gl.txt gets UpdateAssassin.cpp. No other line is needed: of its callees, hasUnitReachedDestination
and resumeMovementIfNoAttackTarget are on main's list already, and the function reads 100.0% with the list as it
is.

reccmp in a build of main's whole /GL list (the 133 files that exist) and this file, with the header commit and
every resolver of those files on: UpdateAssassin 100.0% raw and normalised, no differing line. Each of the 143
functions of main's list reads the same as in the same build of main (3458fea) without the header commit and
the file.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Gynt <gynt@users.noreply.github.com>
gynt and others added 2 commits December 2, 2026 16:17
Main merged #392, which carries this branch's 100% ViewportRenderState
functions in a later, restyled form (named constants, Ghidra field renames).

- Headers (Globals INT_00ed314c/INT_00ed3154, ColorUnion.hpp,
  ViewportRenderState.hpp): main's version.
- The 16 .cpp files both sides added (add/add) are functions main already
  has at 100% (including renderDebugDataMousePointing, 86.9% here): main's
  version.
- status: main's lines, plus this branch's partial entries that main still
  had as Pending.
- compiler-flags-gl.txt: main's list plus this branch's three
  resetupViewport/setupViewport/setViewportBasedOnMapSize lines.
- tools: quick_diff.py keeps this branch's main()-based CLI (-r/-l/--runs/
  --sbs) and gains main's -d and --name; d/ibase/secs/off stay module-level
  so main's quick_gl.py can still point the disassembler at its DLL.
  quick_styles.py keeps the three-score table and adopts main's rule that
  the source as it stands wins a tie. README rows combined.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Follow main's Ghidra renames in the five sources main does not have:
- ViewportState::mouseTile -> mouseFlatTile
- Building::field_0xc2 -> targetMarker (with the BTM_* constants)
- DAT_00ed314c / DAT_00ed3154 -> INT_00ed314c / INT_00ed3154
- Entity, Floater, Tree, TextManager and ViewportRenderState field renames
  in renderMap (refactor_struct_fields.py)
- ColorUnion has no ushortValue view on main: read COL_MAGENTA through
  (ushort)shortValue instead of changing the header.

All 18 functions that were 100% before the merge are still 100%; the partial
ones keep their raw match (renderMap normalized 41.4 -> 40.9).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
gynt and others added 4 commits December 4, 2026 00:12
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…0x64

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…regs

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
gynt and others added 2 commits December 5, 2026 06:20
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…ions

setupViewport, computeMouseTileFromScreenPosition and
renderAssassinClimbingOverlay keep their percentages; the remarks now
name what stops each one.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant